package marksys.free.com.marksys.nettool.retrofit;

import android.app.Application;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;


import marksys.free.com.marksys.nettool.Constant;
import marksys.free.com.marksys.ui.user.LoginActivity;
import marksys.free.com.marksys.utils.SharedPreferencesUtils;
import okhttp3.Interceptor;
import okhttp3.Request;
import marksys.free.com.marksys.utils.Md5;


/**
 * Created by zlinsun on 2018/7/31.
 * hah
 */
public class BaseInterceptor implements Interceptor {

    public static Map<String, String> headers =new HashMap<>();

    public BaseInterceptor() {
    }

    public BaseInterceptor(Map<String, String> headers) {
        this.headers = headers;
    }

    @Override
    public okhttp3.Response intercept(Chain chain) throws IOException {

        Request.Builder builder = chain.request()
                .newBuilder();
        //这里统一处理header
      //  Data time=   System.currentTimeMillis()/1000+"";
        String  token = SharedPreferencesUtils.getString(  Constant.UserToken,"");
        headers.put("Token",token);

        if (headers != null && headers.size() > 0) {
            Set<String> keys = headers.keySet();
            for (String headerKey : keys) {
                builder.addHeader(headerKey,   headers.get(headerKey)).build();
            }
        }

        return chain.proceed(builder.build());

    }
}
